﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.views.components {
    import reprise.ui.*;
    import flash.events.*;
    import reprise.events.*;
    import flash.display.*;
    import reprise.controls.*;
    import flash.utils.*;
    import net.wooga.pets.utils.*;

    public class PointsDisplay extends UIComponent {

        private var _icon:MovieClip;
        private var _label:Label;
        private var _differenceLabel:Label;
        private var _pointsOld:int;
        private var _coins:int;
        private var _targetPoints:int;
        private var _labelStepper:Timer;
        private var _initFirstTime:Boolean = true
        private var _pointsQueue:Array;
        private var _isAnimationPlaying:Boolean;// = false

        public function PointsDisplay(_arg1:String){
            this._pointsQueue = new Array();
            super();
            this._icon = AssetsLibrary.getMovieClip(_arg1);
        }
        public function setCoins(_arg1:int):void{
            this._pointsQueue.push(_arg1);
            this.playAnimation();
        }
        override protected function initialize():void{
            super.initialize();
            addCSSClass("pointsDisplay");
        }
        override protected function createChildren():void{
            addChild(this._icon);
            this._icon.gotoAndStop(1);
            this._label = Label(addComponent("showcardGothicFontOutline pointLabel", null, Label));
            this._label.setLabel("0");
            this._differenceLabel = Label(addComponent("showcardGothicFontOutline differenceLabel", null, Label));
        }
        private function playAnimation():void{
            if (((this._isAnimationPlaying) || ((this._pointsQueue.length <= 0)))){
                return;
            };
            var _local1:int = this._pointsQueue.shift();
            if (_local1 == this._pointsOld){
                this.playAnimation();
                return;
            };
            var _local2 = "";
            if (_local1 > this._pointsOld){
                _local2 = ("+" + (_local1 - this._pointsOld));
            } else {
                if (_local1 < this._pointsOld){
                    _local2 = ("-" + (this._pointsOld - _local1));
                };
            };
            this.labelStepperAnimation(_local1);
            this._differenceLabel.setLabel(_local2);
            this._pointsOld = _local1;
            if (this._initFirstTime){
                this._initFirstTime = false;
                this._isAnimationPlaying = false;
            } else {
                this._icon.gotoAndPlay(1);
                this._differenceLabel.addEventListener(TransitionEvent.ALL_TRANSITIONS_COMPLETE, this.onAnimationComplete);
                this._differenceLabel.addCSSClass("show");
                this._isAnimationPlaying = true;
            };
        }
        private function onAnimationComplete(_arg1:TransitionEvent):void{
            this._differenceLabel.removeEventListener(TransitionEvent.ALL_TRANSITIONS_COMPLETE, this.onAnimationComplete);
            this._differenceLabel.addEventListener(TransitionEvent.ALL_TRANSITIONS_COMPLETE, this.onOutroComplete);
            this._differenceLabel.removeCSSClass("show");
        }
        private function onOutroComplete(_arg1:TransitionEvent):void{
            this._differenceLabel.removeEventListener(TransitionEvent.ALL_TRANSITIONS_COMPLETE, this.onOutroComplete);
            this._isAnimationPlaying = false;
            this.playAnimation();
        }
        private function labelStepperAnimation(_arg1:int):void{
            if (this._initFirstTime){
                this._coins = (this._targetPoints = _arg1);
            };
            this._targetPoints = _arg1;
            if (this._labelStepper == null){
                this._labelStepper = new Timer(20);
            };
            this._labelStepper.addEventListener(TimerEvent.TIMER, this.onLabelStep);
            this._labelStepper.start();
        }
        private function onLabelStep(_arg1:TimerEvent):void{
            if (this._coins != this._targetPoints){
                this._coins = ((this._targetPoints)>this._coins) ? (this._coins + 1) : (this._coins - 1);
                this._label.setLabel(String(this._coins));
            } else {
                this._labelStepper.removeEventListener(TimerEvent.TIMER, this.onLabelStep);
                this._labelStepper.stop();
                this._label.setLabel(String(this._coins));
            };
        }

    }
}//package net.wooga.pets.views.components 
